<?php
namespace app\api\controller\v1;
use think\facade\Cookie;
use think\Db;
use GatewayWorker\Lib\Gateway;
class Tsubscribe extends Base{
	
	
	
	public function get_subscribe_list(){
		
		$data=input('post.');
		if(empty($data['user_id'])){
			return toError(0,'操作错误');
		}
		
		$where['p.user_id']=$data['user_id'];
		if(isset($data['type']) && $data['type']!='-1'){
			$where['p.status']=$data['type'];
		}
		$page=input('page',1);
		$limit=input('limit',10);
		$subscribe=Db::name('process p')->join('subscribe s','p.s_id=s.id','left')->field("p.id,p.status,s.id s_id,s.name,s.remark,s.item_ids,FROM_UNIXTIME(s.add_time,'%Y-%m-%d') as y_add_time")->where($where)->page($page,$limit)->select();
		foreach($subscribe as $k=>$v){
			$subscribe[$k]['staff_type_name']=Db::name('staff_type')->where('id','in',$v['item_ids'])->column('name');
		}
		$conut=Db::name('process p')->where($where)->count();
		return toSuccess('获取成功',$subscribe,$conut,ceil($conut/$limit));
		
		
	}
	
	/*接收预约*/
	public function up_process(){
		$data=input('post.');
		if(empty($data['user_id'])){
			return toError(0,'user_id操作错误');
		}
		if(empty($data['pr_id'])){
			return toError(0,'pr_id操作错误');
		}
		$up=['status'=>1,'update_time'=>time()];
		if(!empty($data['visit_time'])){
			$up['visit_time']=$data['visit_time'];
		}
		if(Db::name('process')->where('id',$data['pr_id'])->update($up)){
			return toSuccess('操作成功');
		}else{
			return toError(0,'操作异常');
		}
	}
	
	
	/*预约项目详情*/
	public function get_process_info(){
		$data=input('post.');
		if(empty($data['user_id'])){
			return toError(0,'操作错误');
		}
		if(empty($data['pr_id'])){
			return toError(0,'pr_id操作错误');
		}
		$subscribe=Db::name('process p')
		->join('subscribe s','p.s_id=s.id','left')
		->field("p.s_id,p.t_id,p.status,s.name,s.remark,s.item_ids,s.address,s.long,s.lat,s.order,s.id s_id,FROM_UNIXTIME(s.add_time,'%Y-%m-%d') as y_add_time,FROM_UNIXTIME(p.add_time,'%Y-%m-%d %H:%i:%s') as x_add_time")->where(['p.user_id'=>$data['user_id'],'p.id'=>$data['pr_id']])->find();
		$subscribe['staff_type_name']=Db::name('staff_type')->where('id','in',$subscribe['item_ids'])->column('name');
		
		if($subscribe["t_id"]==5){
			if(Db::name("measure")->where(["user_id"=>$data['user_id'],"s_id"=>$subscribe["s_id"]])->where("status","in","1,2,4")->find()){
				$subscribe["open"]=false;
			}else{
				$subscribe["open"]=true;
			}
		}
		
		if($subscribe["t_id"]==6){
			if(Db::name("offer")->where(["user_id"=>$data['user_id'],"s_id"=>$subscribe["s_id"]])->where("status","in","1,2,4")->find()){
				$subscribe["open"]=false;
			}else{
				$subscribe["open"]=true;
			}
		}
		
		return toSuccess('获取成功',$subscribe);
	}
	
	public function file_data_list(){
		$data=input('post.');
		if(empty($data['user_id'])){
			return toError(0,'操作错误');
		}
		if(empty($data['type'])){
			return toError(0,'type操作错误');
		}
		if(empty($data['s_id'])){
			return toError(0,'s_id操作错误');
		}
		$data1['indoor_type']=Db::name('indoor_type')->where('status',1)->field('id,name')->order('sort asc')->select();
		$data1['file_data_list']=Db::name('file_data')->where(['type'=>$data['type'],'s_id'=>$data['s_id']])->field('id,file_src,indoor_type_id,name')->select();
		return toSuccess('获取成功',$data1);
	}
	
	
	public function add_file_data(){
		$data=input('post.');
		if(empty($data['user_id'])){
			return toError(0,'操作错误');
		}
		if(empty($data['s_id'])){
			return toError(0,'s_id操作错误');
		}
		if(empty($data['type'])){
			return toError(0,'type操作错误');
		}
		if(empty($data['indoor_type_id'])){
			return toError(0,'indoor_type_id操作错误');
		}
		if(empty($data['file_src'])){
			return toError(0,'file_src操作错误');
		}
		$data['add_time']=time();
		
		
		$data['p_id']=Db::name('process')->where(['user_id'=>$data['user_id'],'s_id'=>$data['s_id']])->value('id');
		if(Db::name('file_data')->insert($data)){
			return toSuccess('上传成功');
		}else{
			return toError(202,'操作失败，请稍后再试');
		}
		
	}
	
	public function del_file_data(){
		$data=input('post.');
		if(empty($data['user_id'])){
			return toError(0,'操作错误');
		}
		if(empty($data['f_id'])){
			return toError(0,'f_id操作错误');
		}
		
		$info=Db::name('file_data')->where('id',$data['f_id'])->find();
		if(empty($info)){
			return toError(0,'操作错误');
		}
		if($info['user_id']!=$data['user_id']){
			return toError(0,'当前文件不是你上传的');
		}
		if(Db::name('file_data')->where('id',$data['f_id'])->delete()){
			return toSuccess('删除成功');
		}else{
			return toError(202,'操作失败，请稍后再试');
		}
	}
	
	
	public function add_offer(){
		$data=input('post.');
		if(empty($data['user_id'])){
			return toError(0,'操作错误');
		}
		if(empty($data['s_id'])){
			return toError(0,'s_id操作错误');
		}
		if($data['staff_type_id']==5){
			
			$measure_info=Db::name('measure')->where(['user_id'=>$data['user_id'],'s_id'=>$data['s_id']])->where("status","in","1,2,4")->find();
			if(!empty($measure_info)){
					return toSuccess('已提交过，等待反馈结果吧');
			}
			unset($data['staff_type_id']);
			unset($data['money']);
			// if(empty($data['mianji'])){
			// 	return toError(0,'mianji操作错误');
			// }
			// if(empty($data['huxing'])){
			// 	return toError(0,'huxing操作错误');
			// }
			
			$data['add_time']=time();
			$data['status']=4;
		
		
			$info=Db::name('subscribe')->where('id',$data['s_id'])->find();
			if($info['allot_id']!=$data['user_id']){
				return toError(0,'你没有操作权限');
			}
			
			if(Db::name('measure')->insert($data)){
				Db::name('process')->where(["user_id"=>$data['user_id'],"s_id"=>$data['s_id']])->update(["update_time"=>time(),'status'=>2]);
				return toSuccess('操作成功');
			}else{
				return toError(202,'操作失败，请稍后再试');
			}
			
			
			
		}
		
		if($data['staff_type_id']==6){
			
			$offer_info=Db::name('offer')->where(['user_id'=>$data['user_id'],'s_id'=>$data['s_id']])->where("status","in","1,2,4")->find();
			if(!empty($offer_info)){
					return toSuccess('已提交过，等待反馈结果吧');
			}
			
			unset($data['staff_type_id']);
			$data['add_time']=time();
			// if(empty($data['mianji'])){
			// 	return toError(0,'mianji操作错误');
			// }
			// if(empty($data['huxing'])){
			// 	return toError(0,'huxing操作错误');
			// }
			// if(empty($data['money'])){
			// 	return toError(0,'money操作错误');
			// }
			$info=Db::name('subscribe')->where('id',$data['s_id'])->find();
			if($info['allot_id']!=$data['user_id']){
				return toError(0,'你没有操作权限');
			}
			if(Db::name('offer')->insert($data)){
				return toSuccess('操作成功');
			}else{
				return toError(202,'操作失败，请稍后再试');
			}
		}
		
		
		
		
		
	}
	
	
	public function open_offer(){
		$data=input('post.');
		if(empty($data['user_id'])){
			return toError(0,'操作错误');
		}
		if(empty($data['s_id'])){
			return toError(0,'s_id操作错误');
		}
		$data=Db::name('measure')->where('s_id',$data['s_id'])->where('status',4)->find();
		if(empty($data)){
			return toError(0,'s_id操作错误');
		}
		return toSuccess('操作成功',$data);
	}
	
	
	
	public function get_assign_people(){
		$data=input('post.');
		if(empty($data['user_id'])){
			return toError(0,'操作错误');
		}
		if(empty($data['s_id'])){
			return toError(0,'s_id操作错误');
		}
		
		$subscribe=Db::name('subscribe')->where(['id'=>$data['s_id']])->find();
		
		if(empty($subscribe)){
			return toError(0,'s_id操作错误');
		}
		
		//获取团长信息
		$data1['team_id']=$subscribe['allot_id'];
		$data1['team_chief']=Db::name('user u')->where('u.id',$data['user_id'])->join('staff_type s','u.staff_type=s.id','left')->field('u.id,u.head_img,u.username,s.name')->find();
		$data1['staff_type_name']=Db::name('staff_type')->where('id','in',$subscribe['item_ids'])->field('id,name')->select();
		
		$data1['team_member']=Db::name('user u')->where('u.team_id',$subscribe['allot_id'])->where('staff_type','in',$subscribe['item_ids'])->where("u.id!=".$data['user_id'])->join('staff_type s','u.staff_type=s.id','left')->field('u.id,u.head_img,u.username,s.name staff_type_name,u.staff_type')->select();
		
		return toSuccess('获取成功',$data1);
	}
	
	public function add_assign_people(){
		$data=input('post.');
		if(empty($data['user_id'])){
			return toError(0,'操作错误');
		}
		if(empty($data['s_id'])){
			return toError(0,'s_id操作错误');
		}
		
		if(empty($data['user_ids'])){
			return toError(0,'user_ids操作错误');
		}
		if(empty($data['team_id'])){
			return toError(0,'team_id操作错误');
		}
		
		$process_info=Db::name('process')->where(['user_id'=>$data['user_id'],"s_id"=>$data['s_id']])->find();
		if(empty($process_info)){
			return toError(0,'s_id操作错误');
		}
		if($process_info['status']==1){
			return toError(0,'项目已开工，不能重复分配');
		}
		
		$user_list=Db::name('user')->where('id','in',$data['user_ids'])->field('staff_type,id')->select();
		$all=[];
		foreach($user_list as $k=>$v){
			if(!Db::name('process')->where(['user_id'=>$v['id'],"s_id"=>$data['s_id']])->find()){
				$all[$k]['user_id']		=$v['id'];
				$all[$k]['t_id']		=$v['staff_type'];
				$all[$k]['s_id']		=$data['s_id'];
				$all[$k]['add_time']	=time();
				$all[$k]['team_id']		=$data['team_id'];	
				$all[$k]['status']		=1;
			}
		}
		
		if(empty($all)){
			return toError(0,'数据异常');
		}
		if(Db::name('process')->insertAll($all)){
			Db::name('process')->where(['user_id'=>$data['user_id'],"s_id"=>$data['s_id']])->update(["status"=>1,'update_time'=>time()]);
			return toSuccess('操作成功');
		}else{
			return toError(0,'操作错误');
		}
		
	}
	
	
	
	public function open_report(){
		$data=input('post.');
		if(empty($data['user_id'])){
			return toError(0,'操作错误');
		}
		if(empty($data['s_id'])){
			return toError(0,'s_id操作错误');
		}
		
		$subscribe=Db::name('subscribe')->where('id',$data['s_id'])->field('name,mobile,address,long,lat,order,allot_id')->find();
		if(empty($subscribe)){
			return toError(0,'s_id操作错误');
		}
		
		$data1['subscribe']=$subscribe;
		$data1['report_type']=Db::name('report_type')->where('is_show',1)->order('sort asc')->field('id r_id,name report_type_name')->select();
		$data1['number_people']=Db::name('process')->where('team_id',$subscribe['allot_id'])->count();
		return toSuccess('请求成功',$data1);
	}
	
	public function add_report(){
		$data=input('post.');
		if(empty($data['user_id'])){
			return toError(0,'操作错误');
		}
		if(empty($data['s_id'])){
			return toError(0,'s_id操作错误');
		}
		if(empty($data['r_id'])){
			return toError(0,'r_id操作错误');
		}
		
		if(empty($data['date_time'])){
			return toError(0,'date_time操作错误');
		}
		if(empty($data['content']) && empty($data['imgs'])){
			return toError(0,'内容不能为空');
		}
		$data['add_time']=time();
		Db::name('report')->insert($data);
		return toSuccess('操作成功');
	}
	
	
	
	
	public function to_assign_people(){
		$data=input('post.');
		if(empty($data['user_id'])){
			return toError(0,'操作错误');
		}
		if(empty($data['s_id'])){
			return toError(0,'s_id操作错误');
		}
		
		$subscribe=Db::name('subscribe')->where(['id'=>$data['s_id']])->find();
		
		if(empty($subscribe)){
			return toError(0,'s_id操作错误');
		}
		
		//获取团长信息
		$data1['team_id']=$subscribe['allot_id'];
		$data1['team_chief']=Db::name('user')->where('id',$data['user_id'])->field('id user_id,head_img,username,staff_type')->find();
		
		$data1['team_chief']['staff_type_name']=Db::name("staff_type")->where("id","in",$data1['team_chief']['staff_type'])->column('name');
		
		$team_member=Db::name('user')->where("team_id",$subscribe['allot_id'])->where('id',"not in",$data['user_id'])->where("staff_type","not in","5,6")
		->field('id,head_img,username,staff_type')
		->select();
		
		
		foreach($team_member as $k=>$v){
			$team_member[$k]['staff_type_name']=implode(",",Db::name("staff_type")->where("id","in",$v['staff_type'])->column('name'));
			if(Db::name('process')->where(['s_id'=>$data['s_id'],'user_id'=>$v['id']])->where('status','in','1,2')->find()){
				$team_member[$k]['f_status']=1;
			}else{
				$team_member[$k]['f_status']=0;
			}
		}
		$data1['team_member']=$team_member;
		return toSuccess('获取成功',$data1);
	}
	
	public function toc_assign_people(){
		$data=input('post.');
		if(empty($data['user_id'])){
			return toError(0,'操作错误');
		}
		if(empty($data['s_id'])){
			return toError(0,'s_id操作错误');
		}
		
		// if(empty($data['user_ids'])){
		// 	return toError(0,'user_ids操作错误');
		// }
		if(empty($data['team_id'])){
			return toError(0,'team_id操作错误');
		}
		
		$process_info=Db::name('process')->where(['user_id'=>$data['user_id'],"s_id"=>$data['s_id']])->find();
		if(empty($process_info)){
			return toError(0,'s_id操作错误');
		}
		Db::name('process')->where(["s_id"=>$data['s_id'],'team_id'=>$process_info['team_id']])->where('id','not in',$process_info['id'])->update(["status"=>3,"update_time"=>time()]);
		$user_list=Db::name('user')->where('id','in',$data['user_ids'])->field('staff_type,id')->select();
		$all=[];
		foreach($user_list as $k=>$v){
			$p_info=Db::name('process')->where(['user_id'=>$v['id'],"s_id"=>$data['s_id']])->find();
			if(!$p_info){
				$all[$k]['user_id']		=$v['id'];
				$all[$k]['t_id']		=$v['staff_type'];
				$all[$k]['s_id']		=$data['s_id'];
				$all[$k]['add_time']	=time();
				$all[$k]['team_id']		=$data['team_id'];	
				$all[$k]['status']		=1;
			}else{
				Db::name('process')->where('id',$p_info['id'])->update(["status"=>1,"update_time"=>time()]);
			}
		}
		
		if(!empty($all)){
			Db::name('process')->insertAll($all);
		}
		return toSuccess('操作成功');
		
	}
	
	
	
	
	
	
	
	
	public function get_jindu(){
		$data=input('post.');
		if(empty($data['user_id'])){
			return toError(0,'操作错误');
		}
		if(empty($data['s_id'])){
			return toError(0,'s_id操作错误');
		}
		$data1	=Db::name('process p')
				->join('user u','p.user_id=u.id','left')
				->join('staff_type s','p.t_id=s.id','left')->where('p.s_id',$data['s_id'])->order('p.add_time desc')
				->field("p.id pr_id,p.status,u.username,u.head_img,s.name staff_type_name,FROM_UNIXTIME(p.add_time,'%Y-%m-%d %H:%i')")->select();
		return toSuccess('获取成功',$data1);
	}
	
	public function jindu_info(){
		$data=input('post.');
		if(empty($data['user_id'])){
			return toError(0,'操作错误');
		}
		if(empty($data['s_id'])){
			return toError(0,'s_id操作错误');
		}
		
		if(empty($data['pr_id'])){
			return toError(0,'pr_id操作错误');
		}
		
		$subscribe=Db::name('subscribe')->where('id',$data['s_id'])->find();
		
		if(empty($subscribe)){
			return toError(0,'s_id操作错误');
		}
		
		if($subscribe['is_allot']==1){
			$data1['team_id']=Db::name('team')->where('id',$subscribe['allot_id'])->value('t_id');
		}
		$data1['name']=Db::name('staff_type')->where('id','in',$subscribe['item_ids'])->column('name');
		$process=Db::name('process')->where('id',$data['pr_id'])->field("*,FROM_UNIXTIME(add_time,'%Y-%m-%d') t_add_time")->find();
		$data1['staff_type_name']=Db::name('staff_type')->where('id',$process['t_id'])->value('name');
		$data1['add_time']=$process['t_add_time'];
		$data1['status']=$process['status'];
		if($process["t_id"]==5){
			//测量大小
			$data1['mianji']=Db::name('measure')->where(["user_id"=>$process["user_id"],"s_id"=>$data['s_id']])->value("mianji");
		}
		if($process["t_id"]==6){
			//报价金额
			$data1['money']=Db::name('offer')->where(["user_id"=>$process["user_id"],"s_id"=>$data['s_id']])->value("money");
		}
		
		$data1['imgs']=Db::name('file_data')->where('p_id',$data['pr_id'])->column('file_src');
		return toSuccess('获取成功',$data1);
	}
	
	public function add_ca_ok(){
		$data=input('post.');
		if(empty($data['user_id'])){
			return toError(0,'操作错误');
		}
		if(empty($data['s_id'])){
			return toError(0,'s_id操作错误');
		}
		
		if(empty($data['pr_id'])){
			return toError(0,'pr_id操作错误');
		}
		
		$subscribe=Db::name('subscribe')->where('id',$data['s_id'])->find();
		
		if(empty($subscribe)){
			return toError(0,'s_id操作错误');
		}
		
		Db::name('process')->where('id',$data['pr_id'])->update(['status'=>2,'update_time'=>time()]);
		return toSuccess('操作成功');
	}
	
	
	public function open_clock(){
		$data=input('post.');
		$date_time=date('Y-m-d');
		if(empty($data['user_id'])){
			return toError(0,'操作错误');
		}
		if(empty($data['s_id'])){
			return toError(0,'s_id操作错误');
		}
		$data1['clock_list']=Db::name('clock')->where(["s_id"=>$data['s_id'],"user_id"=>$data['user_id'],"date_time"=>$date_time])
							->field("*,FROM_UNIXTIME(add_time,'%H:%i') add_time")
							->order('add_time asc')->select();
		$data1['subscribe']=Db::name('subscribe')->where('id',$data['s_id'])->field('address,long,lat,item_ids')->find();
		$data1['staff_type_name']=Db::name('staff_type')->where('id','in',$data1['subscribe']['item_ids'])->column('name');
		return toSuccess('获取成功',$data1);
	}
	public function add_clock(){
		$data=input('post.');
		if(empty($data['user_id'])){
			return toError(0,'操作错误');
		}
		if(empty($data['s_id'])){
			return toError(0,'s_id操作错误');
		}
		if(empty($data['address'])){
			return toError(0,'address操作错误');
		}
		if(empty($data['long'])){
			return toError(0,'long操作错误');
		}
		if(empty($data['lat'])){
			return toError(0,'long操作错误');
		}
		if(empty($data['t_id'])){
			return toError(0,'long操作错误');
		}
		$date_time=date('Y-m-d');
		$data['date_time']=date('Y-m-d');
		$data['add_time']=time();
		$data['is_morning']=GetDateTime();
		
		if(!Db::name('clock')->where(["s_id"=>$data['s_id'],"user_id"=>$data['user_id'],"date_time"=>$date_time,"is_morning"=>$data['is_morning']])->find()){
			$data1=Db::name('clock')->insert($data);
			return toSuccess('打卡成功',$data1);
		}else{
			return toSuccess('请不要重复打卡',$data1);
		}
		
		
		
	}
	
	
	
	public function tuan_tijiao(){
		$data=input('post.');
		if(empty($data['user_id'])){
			return toError(0,'操作错误');
		}
		if(empty($data['s_id'])){
			return toError(0,'s_id操作错误');
		}
		
		$subscribe=Db::name('subscribe')->where('id',$data['s_id'])->find();
		
		if(empty($subscribe)){
			return toError(0,'s_id操作错误');
		}
		if(Db::name("process")->where(["s_id"=>$data['s_id'],"user_id"=>$data['user_id'],"status"=>2])){
			return toError(0,'请不要重复提交');
		}
		
		if(Db::name("process")->where(["s_id"=>$data['s_id'],"team_id"=>$subscribe["allot_id"],"status"=>1])->find()){
			return toError(0,'存在有员工进度未完成');
		}
		
		Db::name("process")->where(["s_id"=>$data['s_id'],"user_id"=>$data['user_id']])->update(["status"=>2,"update_time"=>time(),"complete_time"=>time()]);
		Db::name("subscribe")->where("id",$data['s_id'])->update(["x_status"=>2,"update_time"=>time()]);
		
		return toSuccess('操作成功');
	}
	
	
	//聊天客户列表
	public function user_chat_list(){
		$data=input('post.');
		if(empty($data['user_id'])){
			return toError(0,'操作错误');
		}
		
		$data1=Db::name('process p')->join('subscribe s','p.s_id=s.id','left')
		->join('user u','s.user_id=u.id','left')->field('u.id to_id,u.username,u.head_img,s.mobile,s.item_ids')->group('u.id')->where('u.id','not in',$data['user_id'])
		->where(['p.user_id'=>$data['user_id']])->order('p.add_time desc')->select();
		foreach($data1 as $k=>$v){
			$data1[$k]["item_type_name"]=Db::name("staff_type")->where("id","in",$v["item_ids"])->column('name');
		}
		return toSuccess('请求成功',$data1);
		
	}
	
	
	
	//给某个客户发信息
	public function add_chat(){
		$data=input('post.');
		if(empty($data['user_id'])){
			return toError(0,'操作错误');
		}
		if(empty($data['to_id'])){
			return toError(0,'to_id操作错误');
		}
		if(!isset($data['content_type'])){
			return toError(0,'content_type操作错误');
		}
		if(empty($data['content'])){
			return toError(0,'content操作错误');
		}
		
		$data["add_time"]=time();
		if(Db::name("chat_log")->insert($data)){
			if(Gateway::isUidOnline($data['to_id'])){
				$data["type"]="chat";
				$req_data = json_encode($data, true);
				Gateway::sendToUid($data['to_id'],$req_data);
			}
			return toSuccess('发送成功');
		}else{
			return toError(0,'发送失败');
		}
	}
	//获取聊天记录
	public function chat_log(){
		$data=input('post.');
		if(empty($data['user_id'])){
			return toError(0,'操作错误');
		}
		if(empty($data['to_id'])){
			return toError(0,'to_id操作错误');
		}
		
		$where["user_id"]=[$data['user_id'],$data['to_id']];
		$where["to_id"]=[$data['to_id'],$data['user_id']];
		$data1["list"]=array_reverse(Db::name("chat_log")->where($where)->order('add_time desc')->select());
		$data1["to_user_info"]=Db::name("user")->where('id',$data['to_id'])->field('id to_id,username,head_img')->find();
		return toSuccess('请求成功',$data1);
	}
	
	
	public function user_get_date(){
		
		$data=input('post.');
		if(empty($data['user_id'])){
			return toError(0,'操作错误');
		}
		
		if(empty($data['date'])){
			return toError(0,'date操作错误');
		}
		$start_day 	= date($data['date'].'-01', time());
	    $end_day   	= date('Y-m-d', strtotime("{$start_day} + 1 month -1 day"));
	    $start_day1	=str_replace("-","",$start_day);
	    $end_day1	=str_replace("-","",$end_day);
		$date_count=count(range($start_day1,$end_day1));
		$data1=[];
		$data1["count"]=0;
		for($i=1;$i<=$date_count;$i++){
			$k=$i-1;
			if(strlen($i)==1){
				$r=$data['date']."-0".$i;
			}else{
				$r=$data['date']."-".$i;
			}
			$data1[$k]["date"]=$r;
			$data1[$k]["data"]=Db::name("clock")->where(["user_id"=>$data['user_id'],"date_time"=>$r])
			->field("*,FROM_UNIXTIME(add_time,'%H:%i') add_time")->order("is_morning asc")->select();
			if(count($data1[$k]["data"])==2){
				$data1["count"]++;
			}
			
		}
		return toSuccess('请求成功',$data1);

		
	}
	
	public function authentication(){
		$data=input('post.');
		if(empty($data['user_id'])){
			return toError(0,'操作错误');
		}
		if(empty($data['real_name'])){
			return toError(0,'real_name操作错误');
		}
		if(empty($data['sex'])){
			return toError(0,'sex操作错误');
		}
		if(empty($data['card'])){
			return toError(0,'card操作错误');
		}
		if(empty($data['huji'])){
			return toError(0,'huji操作错误');
		}
		if(empty($data['imgs'])){
			return toError(0,'imgs操作错误');
		}
		if(empty($data['staff_type'])){
			return toError(0,'staff_type操作错误');
		}
		$data["update_time"]=time();
		$data["audit_status"]=1;
		$user_id=$data['user_id'];
		unset($data['user_id']);
		if(Db::name("user")->where("id",$user_id)->update($data)){
			return toSuccess('操作成功');
		}else{
			return toError(0,'操作错误');
		}
		
		
	}
	
	public function staff_type_list(){
		$staff_type_list=Db::name("staff_type")->where(["status"=>1])->field("id,name")->select();
		return toSuccess('请求成功',$staff_type_list);
	}
	
	
	public function add_schedule(){
		$data=input('post.');
		if(empty($data['user_id'])){
			return toError(0,'操作错误');
		}
		if(empty($data['s_id'])){
			return toError(0,'s_id操作错误');
		}
		if(empty($data['schedule'])){
			return toError(0,'schedule操作错误');
		}
		if(Db::name("subscribe")->where("id",$data['s_id'])->update(["schedule"=>$data["schedule"]])){
			return toSuccess('操作成功');
		}else{
			return toError(0,'操作错误');
		}
	}
	
	public function schedule_info(){
		$data=input('post.');
		if(empty($data['user_id'])){
			return toError(0,'操作错误');
		}
		if(empty($data['s_id'])){
			return toError(0,'s_id操作错误');
		}
		$schedule=Db::name("subscribe")->where("id",$data['s_id'])->value('schedule');
		return toSuccess('操作成功',$schedule);
	}
	
	
}
?>